﻿using System;
using System.Data.Linq.Mapping;
using System.Collections.Generic;

using LeanEngine.Entity;
using LeanEngine.Validation;
using LeanEngine.Collections;
using LeanEngine.Data.Linq.Mapping;

namespace LeanEngine.Business.Security.Entity
{
    /// <summary>
    /// Represents an user of the application.
    /// </summary>
    [Serializable]
    [Table(Name = "Membership")]
    public class Membership : ChangeTrackerEntity
    {
        /// <summary>
        /// Initialize a new instance of LeanEngine.Business.Security.TransferObject.Membership class.
        /// </summary>
        public Membership()
        {
            ProfilesList = new ChangeTrackerCollection<UserProfile>();
            AccessExceptionList = new ChangeTrackerCollection<ExceptionPolicy>();
        }

        /// <summary>
        /// Gets or sets the identification of the membership.
        /// </summary>
        [Column(Name = "MembershipID", IsPrimaryKey = true, IsDbGenerated = true)]
        public int ID
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the user name of the membership.
        /// </summary>
        [Column(Name = "UserName")]
        [IsNotEmpty(typeof(Resource.ErrorMessages), "MembershipUsernameRequired")]
        public string UserName
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the password of the membership.
        /// </summary>
        [Column(Name = "Password")]
        [IsNotEmpty(typeof(Resource.ErrorMessages), "MembershipPasswordRequired")]
        public string Password
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the membership name displayed on the application.
        /// </summary>
        [Column(Name = "DisplayName")]
        [IsNotEmpty(typeof(Resource.ErrorMessages), "MembershipDisplayNameRequired")]
        public string DisplayName
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the user profiler list associated to the membership.
        /// </summary>
        [AssociationTable(Name = "MembershipProfile")]
        public ChangeTrackerCollection<UserProfile> ProfilesList
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the list of especial policy associated to the membership.
        /// </summary>
        public ChangeTrackerCollection<ExceptionPolicy> AccessExceptionList
        {
            get;
            private set;
        }
    }
}
